﻿using System;
using System.Collections;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Services;
using System.Web.Services.Protocols;
using System.Xml.Linq;
using Sicurezza.CA.Manager;
using System.Text;

namespace Sicurezza.CA.Server
{
    /// <summary>
    /// Descrizione di riepilogo per $codebehindclassname$
    /// </summary>
    [WebService(Namespace = "http://tempuri.org/")]
    [WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
    public class DownloadHandler : IHttpHandler
    {

        public void ProcessRequest(HttpContext context)
        {
            string Id =context.Request.QueryString["id"];
            string cert = X509Manager.Get(Id);
            byte[] byteCert = ASCIIEncoding.ASCII.GetBytes(cert);
            context.Response.AddHeader("Content-Disposition", "attachment; filename=" + Id + ".pem");
            context.Response.ContentType = "text/plain";
            context.Response.OutputStream.Write(byteCert, 0, byteCert.Length);
        }

        public bool IsReusable
        {
            get
            {
                return false;
            }
        }
    }
}
